# 此模块用于 litemall 系统管理>管理员 模块下的接口管理
import api.base


class ManagerLitemall(api.base.Base):
    def __init__(self):
        self.add_url = self.comb_url('/admin/admin/create')
        self.mod_url = self.comb_url('/admin/admin/update')
        self.del_url = self.comb_url('/admin/admin/delete')
        self.sea_url = self.comb_url('/admin/admin/list')
        self.login()
        self.headers = self.headers()

    def add_manager(self, username, password, opt_para=None):
        add_info = {"username": username, "password": password}
        if opt_para:
            add_info.update(opt_para)
        return self.post_method(self.add_url, add_info, **self.headers)

    def del_manager(self, id, username, password, opt_para=None):
        del_info = {"id": id, "username": username, "password": password}
        if opt_para:
            del_info.update(opt_para)
        return self.post_method(self.del_url, del_info, **self.headers)

    def mod_manager(self, id, username, password, opt_para=None):
        mod_info = {"id": id, "username": username, "password": password}
        if opt_para:
            mod_info.update(opt_para)
        return self.post_method(self.mod_url, mod_info, **self.headers)

    def sea_manager(self, **search_parameters):
        sp = {'page': 1, 'limit': 20, 'sort': 'add_time', 'order': 'desc'}
        if search_parameters:
            sp.update(search_parameters)
        return self.get_method(self.sea_url, sp, **self.headers)


if __name__ == '__main__':
    test = ManagerLitemall()
    print(test.mod_manager(87, '113456', '321456', {"roleIds": [2], "avatar": ""}))
